{include file="public:header" /}
<!--添加采集点-->
<style>
    .html-tag{width:200px;}
    .html-tag li{width:90px;float:left;line-height: 22px;}
</style>
<form id="info_form" action="{:url('add')}" method="post" enctype="multipart/form-data">
    <div class="pad_lr_10">
        <div class="col_tab">
            <ul class="J_tabs tab_but cu_li">
                <li class="current">网址规则</li>
                <li>内容规则</li>
                <li>自定义规则</li>
                <li>高级配置</li>
            </ul>
            <div class="J_panes">
                <div class="content_list pad_10">
                    <fieldset>
                        <legend>基本信息</legend>
                        <table width="100%" class="table_form">
                            <tr>
                                <td width="120">采集项目名：</td>
                                <td>
                                    <input type="text" name="data[name]" id="name"  class="input-text" value="">
                                </td>
                            </tr>
                            <tr>
                                <td width="120">采集页面编码：</td>
                                <td>
                                    <input type="radio" value="gbk" checked="" id="_gbk" name="data[sourcecharset]"> GBK<input type="radio" value="utf-8" id="_utf-8" name="data[sourcecharset]"> UTF-8<input type="radio" value="big5" id="_big5" name="data[sourcecharset]"> BIG5			</td>
                            </tr>
                        </table>
                    </fieldset>
                    <fieldset>
                        <legend>网址采集</legend>
                        <table width="100%" class="table_form">
                            <tr>
                                <td width="120">网址类型：</td>
                                <td>
                                   {volist name="url_list_type" id="vo"}
                                       <input type="radio" id="_{$key}" name="data[sourcetype]" value="{$key}" onclick="show_url_type(this.value)" {if condition="$i eq 1"}checked{/if}/>{$vo}
                                   {/volist}
                                </td>
                            </tr>
                            <tbody id="url_type_1">
                            <tr>
                                <td width="120">网址配置：</td>
                                <td>
                                    <input type="text" name="urlpage1" class="input-text" id="urlpage_1" size="100" value=""> <input type="button" class="btn J_showdialog" data-uri=''  data-acttype="ajax" data-title="测试网址" data-id="testurl" data-width="670" data-height="500" onclick="show_url()" value="测试"><br />
                                    (如：http://www.zhuizhan.com/news/(*).html,页码使用(*)做为通配符。<br />
                                    页码从: <input type="text" name="data[pagesize_start]" value="1" size="4" class="input-text"> 到 <input class="input-text" type="text" name="data[pagesize_end]" value="10" size="4"> 每次增加  <input class="input-text" type="text" name="data[par_num]" size="4" value="1">
                                </td>
                            </tr>
                            </tbody>
                            <tbody id="url_type_2"  class="hidden">
                            <tr>
                                <td width="120">网址配置：</td>
                                <td>
                                    <textarea rows="10" cols="80" class="input-text" name="urlpage2" id="urlpage_2" ></textarea> <br>一行一条
                                </td>
                            </tr>
                            </tbody>
                            <tbody id="url_type_3" class="hidden">
                            <tr>
                                <td width="120">网址配置：</td>
                                <td>
                                    <input type="text" class="input-text" name="urlpage3" id="urlpage_3" size="100" value="">
                                </td>
                            </tr>
                            </tbody>
                            <tbody id="url_type_4" class="hidden">
                            <tr>
                                <td width="120">网址配置：</td>
                                <td>
                                    <input type="text" name="urlpage4" class="input-text" id="urlpage_4" size="100" value="">
                                </td>
                            </tr>
                            </tbody>
                            <tr>
                                <td width="120">网址配置：</td>
                                <td>
                                    网址必须包含：<input type="text" name="data[url_contain]" class="input-text"  value=""> 网址中不得包含 <input type="text" name="data[url_except]" class="input-text"  value="">
                                </td>
                            </tr>
                            <tr>
                                <td width="120">Base配置：</td>
                                <td>
                                    <input type="text" name="data[page_base]" class="input-text"  value="" size="100" ><br>
                                    如果目标网站配置了Base请设置。
                                </td>
                            </tr>
                            <tr>
                                <td width="120">获取网址：</td>
                                <td>
                                    从<textarea rows="10" cols="40" name="data[url_start]"></textarea> 到 <textarea rows="10" name="data[url_end]" cols="40"></textarea> 结束
                                </td>
                            </tr>
                            <tr>
                                <td>链接地址：</td>
                                <td>
                                    从<textarea rows="10" cols="40" name="data[urla_start]"></textarea> 到 <textarea rows="10" name="data[urla_end]" cols="40"></textarea> 结束
                                </td>
                            </tr>
                        </table>
                    </fieldset>

                </div>
                <div class="content_list pad_10 hidden" id="show_div_2">
                    <div class="explain-col">
                        1、匹配规则请设置开始和结束符，具体内容使用“[内容]”做为通配符 。<br>2、过滤选项格式为“要过滤的内容[|]替换值”，要过滤的内容支持正则表达式，每行一条。<br>
                    </div>
                    <input type="button" class="button" value="全部展开" onclick="$('#show_div_2').children('fieldset').children('.table_form').show()"> <input type="button" class="button" value="全部合上" onclick="$('#show_div_2').children('fieldset').children('.table_form').hide()">
                    <fieldset>
                        <legend><a href="javascript:void(0)" onclick="$(this).parent().parent().children('table').toggle()">标题规则</a></legend>
                        <table width="100%" class="table_form">
                            <tr>
                                <td width="120">匹配规则：</td>
                                <td>
                                    <textarea rows="5" cols="40" name="data[title_rule]" id="title_rule"><title>[内容]</title></textarea> <br>使用‘[内容]’作为通配符
                                </td>
                                <td width="120">过滤选项：</td>
                                <td>
                                    <textarea rows="5" cols="40" name="data[title_html_rule]" id="title_html_rule"></textarea>

                                </td>
                                <td width="72">
                                    <input type="button" value="添加" onclick="addHtmlRule('title_html');" class="btn" />
                                </td>
                                <td> {php}$str = '<ul class="html-tag">';{/php}
                                    <ul class="html-tag">

                                        {volist name="html_tag" id="vo"}
                                            {php}
                                                $str .= '<li><input type="checkbox" name="content_html_ID" value="'.htmlspecialchars($key).'" />'.htmlspecialchars($vo).'</li>';
                                            {/php}
                                           <li><input type="checkbox" name="title_html" value="{$key}" />{:htmlspecialchars($vo)}</li>
                                        {/volist}

                                    </ul>
                                    {php}$str.='</ul>';{/php}
                                </td>
                            </tr>
                        </table>
                    </fieldset>
                    <fieldset>
                        <legend><a href="javascript:void(0)" onclick="$(this).parent().parent().children('table').toggle()">作者规则</a></legend>
                        <table width="100%" class="table_form" style="display:none">
                            <tr>
                                <td width="120">匹配规则：</td>
                                <td>
                                    <textarea rows="5" cols="40" name="data[author_rule]" id="author_rule"></textarea>  <br>使用‘[内容]’作为通配符
                                </td>
                                <td width="120">过滤选项：</td>
                                <td>
                                    <textarea rows="5" cols="40" name="data[author_html_rule]" id="author_html_rule"></textarea>
                                </td>
                                <td width="72">
                                    <input type="button" value="添加" onclick="addHtmlRule('author_html');" class="btn" />
                                </td>
                                <td>
                                    <ul class="html-tag">
                                        {volist name="html_tag" id="vo"}
                                        <li><input type="checkbox" name="author_html" value="{$key}" />{:htmlspecialchars($vo)}</li>
                                        {/volist}

                                    </ul>

                                </td>
                            </tr>
                        </table>
                    </fieldset>
                    <fieldset>
                        <legend><a href="javascript:void(0)" onclick="$(this).parent().parent().children('table').toggle()">来源规则</a></legend>
                        <table width="100%" class="table_form" style="display:none">
                            <tr>
                                <td width="120">匹配规则：</td>
                                <td>
                                    <textarea rows="5" cols="40" name="data[comeform_rule]" id="comeform_rule"></textarea> <br>使用‘[内容]’作为通配符
                                </td>
                                <td width="120">过滤选项：</td>
                                <td>
                                    <textarea rows="5" cols="40" name="data[comeform_html_rule]" id="comeform_html_rule"></textarea>
                                </td>
                                <td width="72">
                                    <input type="button" value="添加" onclick="addHtmlRule('comeform_html');" class="btn" />
                                </td>
                                <td>
                                    <ul class="html-tag">
                                        {volist name="html_tag" id="vo"}
                                        <li><input type="checkbox" name="comeform_html" value="{$key}" />{:htmlspecialchars($vo)}</li>
                                        {/volist}

                                    </ul>

                                </td>
                            </tr>
                        </table>
                    </fieldset>
                    <fieldset>
                        <legend><a href="javascript:void(0)" onclick="$(this).parent().parent().children('table').toggle()">时间规则</a></legend>
                        <table width="100%" class="table_form"  style="display:none">
                            <tr>
                                <td width="120">匹配规则：</td>
                                <td>
                                    <textarea rows="5" cols="40" name="data[time_rule]" id="time_rule"></textarea> <br>使用‘[内容]’作为通配符
                                </td>
                                <td width="120">过滤选项：</td>
                                <td>
                                    <textarea rows="5" cols="40" name="data[time_html_rule]" id="time_html_rule"></textarea>
                                </td>
                                <td width="72">
                                    <input type="button" value="添加" onclick="addHtmlRule('time_html');" class="btn" />
                                </td>
                                <td>
                                    <ul class="html-tag">
                                        {volist name="html_tag" id="vo"}
                                        <li><input type="checkbox" name="time_html" value="{$key}" />{:htmlspecialchars($vo)}</li>
                                        {/volist}

                                    </ul>

                                </td>
                            </tr>
                        </table>
                    </fieldset>
                    <fieldset>
                        <legend><a href="javascript:void(0)" onclick="$(this).parent().parent().children('table').toggle()">内容规则</a></legend>
                        <table width="100%" class="table_form" style="display:none">
                            <tr>
                                <td width="120">匹配规则：</td>
                                <td>
                                    <textarea rows="5" cols="40" name="data[content_rule]" id="content_rule"></textarea> <br>使用‘[内容]’作为通配符
                                </td>
                                <td width="120">过滤选项：</td>
                                <td>
                                    <textarea rows="5" cols="40" name="data[content_html_rule]" id="content_html_rule"></textarea>
                                </td>
                                <td width="72">
                                    <input type="button" value="添加" onclick="addHtmlRule('content_html');" class="btn" />
                                </td>
                                <td>
                                    <ul class="html-tag">
                                        {volist name="html_tag" id="vo"}
                                        <li><input type="checkbox" name="content_html" value="{$key}" />{:htmlspecialchars($vo)}</li>
                                        {/volist}
                                    </ul>

                                </td>
                            </tr>
                        </table>
                    </fieldset>
                    <fieldset>
                        <legend><a href="javascript:void(0)" onclick="$(this).parent().parent().children('table').toggle()">分页规则</a></legend>
                        <table width="100%" class="table_form" style="display:none">
                            <tr>
                                <td width="120">分页模式：</td>
                                <td>
                                    <input type="radio" value="1" id="_1" onclick="show_nextpage(this.value)" name="data[content_page_rule]" checked> 全部列出模式<input type="radio" value="2" id="_2" onclick="show_nextpage(this.value)" name="data[content_page_rule]"> 上下页模式			</td>
                            </tr>
                            <tbody id="nextpage" class="hidden">
                            <tr>
                                <td width="120">下一页规则：</td>
                                <td>
                                    <input type="text" class="input-text" name="data[content_nextpage]" size="100" value=""><br>
                                    请填写下一页超链接中间的代码。如：下一页，他的“下一页规则”为“下一页”。
                                </td>
                            </tr>
                            </tbody>
                            <tr>
                                <td width="120">匹配规则：</td>
                                <td>
                                    从 <textarea rows="5" cols="40" name="data[content_page_start]" id="content_page_start"></textarea> 到 <textarea rows="5" cols="40" name="data[content_page_end]" id="content_page_end"></textarea>
                                </td>
                            </tr>
                        </table>
                    </fieldset>
                </div>
                <div class="content_list pad_10 hidden">
                    <input type="button" class="button" value="添加项目" onclick="add_caiji()">
                    <table width="100%" class="table_form" id="customize_config">

                    </table>
                </div>
                <div class="content_list pad_10 hidden">
                    <table width="100%" class="table_form">
                        <tbody><tr>
                            <td width="120">下载图片：</td>
                            <td>
                                <input type="radio" value="1"  name="data[down_attachment]" checked> 下载图片<input type="radio" value="0"  name="data[down_attachment]"> 不下载			</td>
                        </tr>
                        <tr>
                            <td width="120">内容分页：</td>
                            <td>
                                <input type="hidden" value="0" name="data[watermark]"/>
                                <input type="radio" value="0"  name="data[content_page]" checked> 不分页<input type="radio" value="1"  name="data[content_page]"> 按原文分页			</td>
                        </tr>
                        <tr>
                            <td width="120">导入顺序：</td>
                            <td>
                                <input type="radio" value="1"  name="data[coll_order]"> 与目标站相同<input type="radio" value="2"  name="data[coll_order]" checked> 与目标站相反			</td>
                        </tr>
                        </tbody></table>
                </div>
            </div>
            <div class="mt10"><input type="submit" value="提交" id="dosubmit" name="dosubmit" class="btn btn_submit" style="margin:0 0 10px 100px;"><br /><br /><br /></div>
        </div>
    </div>
</form>
{include file="public:footer" /}
<script src="__PUBLIC__/js/plugins/jquery.tools.min.js"></script>
<script>
    $(function(){
        $('ul.J_tabs').tabs('div.J_panes > div');
        $.formValidator.initConfig({formid:"info_form",autotip:true});
        $("#name").formValidator({onshow:'请填写名称',onfocus:'请填写名称'}).inputValidator({min:1,onerror:'请填写名称'});

    });
    function show_url_type(obj) {
        var num = <?php echo count($url_list_type);?>;
        for (var i=1; i<=num; i++){
            if (obj==i){
                $('#url_type_'+i).show();
            } else {
                $('#url_type_'+i).hide();
            }
        }
    }
    function show_url() {
        var type = $("input[type='radio'][name='data[sourcetype]']:checked").val();
        var urlpage = $('#urlpage_'+type).val();
        var pagesize_s = $("input[name='data[pagesize_start]']").val();
        var pagesize_e = $("input[name='data[pagesize_end]']").val();
        var par_num    = $("input[name='data[par_num]']").val();
        var url = '{:url("publishurl")}';
        url += '?sourcetype='+type;
        url += '&urlpage='+encodeURIComponent(urlpage);
        url += '&pagesize_start='+pagesize_s;
        url += '&pagesize_end='+pagesize_e;
        url += '&par_num='+par_num;
        $(".J_showdialog").attr('data-uri',url);
    }
    function show_nextpage(value) {
        if (value == 2) {
            $('#nextpage').show();
        } else {
            $('#nextpage').hide();
        }
    }
    var i=0;
    function add_caiji() {
        var htmlrule = '{$str}';
        htmlrule = htmlrule.replace(new RegExp(/ID/g),i);
        var html = '<tbody id="customize_config_'+i+'"><tr style="background-color:#FBFFE4"><td>规则名称：</td><td><input type="text" name="customize_config[name][]" class="input-text" /></td><td>规则英文名：</td><td><input type="text" name="customize_config[en_name][]" class="input-text" /></td></tr><tr><td width="120">匹配规则：</td><td><textarea rows="5" cols="40" name="customize_config[rule][]" id="rule_'+i+'"></textarea> <br>作用[内容]作为通配符</td><td width="120">过滤选项：</td><td><textarea rows="5" cols="40" name="customize_config[html_rule][]" id="content_html_rule_'+i+'"></textarea></td>';
        html += '<td width="72"><input type="button" value="添加" onclick="addHtmlRule(\'a\','+i+');" class="btn" /> </td>';
        html += '<td>'+htmlrule+'</td>';
        html += '</tr></tbody>';
        $('#customize_config').append(html);
       i++;
    }
function addHtmlRule(n,i){
    var obj = i>=0 ? $("input[name=content_html_"+i+"]:checked") : $("input[name="+n+"]:checked");
    var arr = [];
    obj.each(function(i,n){
        arr.push($(this).val());
    });
    var str = arr.join("\n");
    var id = i>=0 ? '#content_html_rule_'+i : "#"+n+"_rule";
    $(id).val(str);
}
</script>
</body>
</html>